VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmHCsalidaPop 
   BackColor       =   &H00FFFFFF&
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Seleccion de Datos"
   ClientHeight    =   2550
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   7125
   ControlBox      =   0   'False
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2550
   ScaleWidth      =   7125
   StartUpPosition =   3  'Windows Default
   Begin MSComctlLib.ImageList ImageList1 
      Left            =   2280
      Top             =   0
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483643
      ImageWidth      =   16
      ImageHeight     =   16
      MaskColor       =   12632256
      _Version        =   393216
      BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
         NumListImages   =   11
         BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmHCsalidaPop.frx":0000
            Key             =   "IMG1"
         EndProperty
         BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmHCsalidaPop.frx":059A
            Key             =   "IMG2"
         EndProperty
         BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmHCsalidaPop.frx":0B34
            Key             =   "IMG3"
         EndProperty
         BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmHCsalidaPop.frx":10CE
            Key             =   "IMG4"
         EndProperty
         BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmHCsalidaPop.frx":1668
            Key             =   "IMG5"
         EndProperty
         BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmHCsalidaPop.frx":1C02
            Key             =   "IMG6"
         EndProperty
         BeginProperty ListImage7 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmHCsalidaPop.frx":219C
            Key             =   "IMG7"
         EndProperty
         BeginProperty ListImage8 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmHCsalidaPop.frx":2736
            Key             =   "IMG8"
         EndProperty
         BeginProperty ListImage9 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmHCsalidaPop.frx":2CD0
            Key             =   "IMG9"
         EndProperty
         BeginProperty ListImage10 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmHCsalidaPop.frx":326A
            Key             =   "IMG10"
         EndProperty
         BeginProperty ListImage11 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmHCsalidaPop.frx":3804
            Key             =   "IMG11"
         EndProperty
      EndProperty
   End
   Begin MSComctlLib.Toolbar Toolbar1 
      Align           =   1  'Align Top
      Height          =   360
      Left            =   0
      TabIndex        =   5
      Top             =   0
      Width           =   7125
      _ExtentX        =   12568
      _ExtentY        =   635
      ButtonWidth     =   609
      ButtonHeight    =   582
      Appearance      =   1
      Style           =   1
      ImageList       =   "ImageList1"
      _Version        =   393216
      BeginProperty Buttons {66833FE8-8583-11D1-B16A-00C0F0283628} 
         NumButtons      =   5
         BeginProperty Button1 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Style           =   3
         EndProperty
         BeginProperty Button2 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "Aceptar"
            Object.ToolTipText     =   "Aceptar (F5)"
            ImageIndex      =   5
         EndProperty
         BeginProperty Button3 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Style           =   3
         EndProperty
         BeginProperty Button4 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "Salir"
            Object.ToolTipText     =   "Salir (Esc)"
            ImageIndex      =   11
         EndProperty
         BeginProperty Button5 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Style           =   3
         EndProperty
      EndProperty
      BorderStyle     =   1
   End
   Begin VB.Frame frameHor 
      BackColor       =   &H00FFFFFF&
      Caption         =   "Horarios Reservados: Dia - Hora - Profesional - Especialidad"
      Height          =   2055
      Left            =   120
      TabIndex        =   4
      Top             =   360
      Width           =   6855
      Begin VB.OptionButton optHor 
         BackColor       =   &H00FFFFFF&
         Height          =   255
         Index           =   0
         Left            =   120
         TabIndex        =   2
         Top             =   240
         Visible         =   0   'False
         Width           =   6615
      End
   End
   Begin VB.Frame frameProf 
      BackColor       =   &H00FFFFFF&
      Caption         =   "Profesional:"
      Height          =   2055
      Left            =   120
      TabIndex        =   3
      Top             =   360
      Width           =   6855
      Begin VB.ComboBox cmbEsp 
         Height          =   315
         Left            =   1320
         Style           =   2  'Dropdown List
         TabIndex        =   0
         Top             =   600
         Width           =   3975
      End
      Begin VB.ComboBox cmbProf 
         Height          =   315
         Left            =   1320
         Style           =   2  'Dropdown List
         TabIndex        =   1
         Top             =   1080
         Width           =   5415
      End
      Begin VB.Label Label1 
         BackColor       =   &H00FFFFFF&
         Caption         =   "Especialidad:"
         Height          =   255
         Left            =   240
         TabIndex        =   7
         Top             =   600
         Width           =   975
      End
      Begin VB.Label Label2 
         BackColor       =   &H00FFFFFF&
         Caption         =   "Profesional:"
         Height          =   255
         Left            =   240
         TabIndex        =   6
         Top             =   1080
         Width           =   975
      End
   End
End
Attribute VB_Name = "frmHCsalidaPop"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim i As Integer, dato(100, 1 To 5) As String, trabajando As Boolean, con As New ConBaseDatos
Public Tipo As TipoBusHC, Paciente As String

Private Sub optHor_DblClick(Index As Integer)

If Toolbar1.Buttons(2).Enabled Then Toolbar1_ButtonClick Toolbar1.Buttons(2)

End Sub

Private Sub optHor_KeyPress(Index As Integer, KeyAscii As Integer)

If KeyAscii = 13 Then
    KeyAscii = 0
    If Toolbar1.Buttons(2).Enabled Then Toolbar1_ButtonClick Toolbar1.Buttons(2)
End If

End Sub

Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)

Select Case Button.Key
         
    Case "Salir"
        frmHCsalida.Profesional = ""
        frmHCsalida.Turno = ""
        Unload Me
    
    Case "Aceptar"
        If Control Then Exit Sub
        CargarDatos
        Unload Me
        
End Select

End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)

Select Case KeyCode
    Case 27 'Escape "Salir"
        If Toolbar1.Buttons(4).Enabled Then Toolbar1_ButtonClick Toolbar1.Buttons(4)
        
    Case 112 'F1 "Ayuta"
        frmPrincipal.manual_Click
        
    Case 116 'F5 "Aceptar"
        If Toolbar1.Buttons(2).Enabled Then Toolbar1_ButtonClick Toolbar1.Buttons(2)
        
End Select

End Sub

Private Sub Form_Load()

Centrar Me
Me.Icon = frmPrincipal.Icon
BusDatos

End Sub

Private Sub cmbEsp_Change()

If trabajando Then Exit Sub
trabajando = True

CargarProfesionales

trabajando = False

End Sub

Private Sub cmbEsp_Click()

If trabajando Then Exit Sub
trabajando = True

CargarProfesionales

trabajando = False

End Sub

Private Sub cmbEsp_GotFocus()

cmbEsp.BackColor = &HFFFFC0

End Sub

Private Sub cmbEsp_KeyPress(KeyAscii As Integer)

Select Case KeyAscii
    Case 13
        SendKeys "{TAB}"
        KeyAscii = 0

    Case 8, 32
        cmbProf.Clear
        cmbEsp.ListIndex = -1
        
End Select

End Sub

Private Sub cmbEsp_LostFocus()

cmbEsp.BackColor = &H80000005

End Sub

Private Sub cmbProf_GotFocus()

cmbProf.BackColor = &HFFFFC0

End Sub

Private Sub cmbProf_KeyPress(KeyAscii As Integer)

Select Case KeyAscii
    Case 13
        KeyAscii = 0
        If Toolbar1.Buttons(2).Enabled Then Toolbar1_ButtonClick Toolbar1.Buttons(2)

    Case 8, 32
        cmbProf.ListIndex = -1

End Select

End Sub

Private Sub cmbProf_LostFocus()

cmbProf.BackColor = &H80000005

End Sub

Private Sub optHor_Click(Index As Integer)

optHor(Index).FontBold = True
optHor(Index).FontUnderline = True

For i = 0 To optHor.UBound
    If i <> Index Then
        optHor(i).FontBold = False
        optHor(i).FontUnderline = False
    End If
    DoEvents
Next i

End Sub

Private Sub CargarEspecialidades()

con.AbrirRegistros "select * from especialidades order by nombre", Consulta
Do While Not con.Registros.EOF
    cmbEsp.AddItem DesEditar(con.Registros("nombre"))
    cmbEsp.ItemData(cmbEsp.NewIndex) = CInt(con.Registros("especialidad"))
    con.Registros.MoveNext
    DoEvents
Loop
con.CerrarRegistros

If cmbEsp.ListCount > 0 Then cmbEsp.ListIndex = 0

End Sub

Private Sub CargarProfesionales()

If cmbEsp.ListIndex = -1 Then Exit Sub

cmbProf.Clear
con.AbrirRegistros "SELECT Profesionales_especialidades.profesional, Profesionales.apellido + ', ' + Profesionales.nombre as nombre FROM Profesionales_especialidades INNER JOIN Profesionales ON Profesionales_especialidades.profesional = Profesionales.profesional where Profesionales_especialidades.especialidad='" & ReplicarCaracter("0", LargoID, cmbEsp.ItemData(cmbEsp.ListIndex)) & "' and profesionales.activo=1 order by 2", Consulta
Do While Not con.Registros.EOF
    cmbProf.AddItem DesEditar(con.Registros("nombre"))
    cmbProf.ItemData(cmbProf.NewIndex) = CInt(con.Registros("profesional"))
    con.Registros.MoveNext
    DoEvents
Loop
con.CerrarRegistros
cmbProf.ListIndex = -1

End Sub

Private Function Control() As Boolean

Control = False
If cmbProf.Text = "" And Tipo = TipoBusHC.Profesional Then
    Control = True
    MsgBox "Seleccione Profesional", vbCritical, "Falta datos de carga"
    cmbProf.SetFocus
    
ElseIf Tipo = TipoBusHC.TurnosPaciente Then
    Control = True
    For i = 0 To optHor.UBound
        If optHor(i).Enabled And optHor(i).Value Then
            Control = False
            Exit For
        End If
        DoEvents
    Next i
    If Control Then MsgBox "Seleccione un horario", vbCritical, "Error de datos"
    
End If

End Function

Private Sub BorrarHorariosPaciente()

'borro los option cargados y reseteo el primero
optHor(0).Enabled = True
optHor(0).Caption = ""
optHor(0).Visible = False
optHor(0).Value = False
optHor(0).FontBold = False
optHor(0).FontUnderline = False
For i = 1 To optHor.Count - 1
    Unload optHor(i)
Next i
frameHor.Height = 2055
Me.Height = 2925

End Sub

Private Sub VerHorariosPaciente(Paciente As String)

BorrarHorariosPaciente

Erase dato

con.AbrirRegistros "SELECT Turnos.turno,Turnos.dia,Turnos.hora,Profesionales.apellido+', '+Profesionales.nombre as profesional,isnull(Especialidades.nombre,'') AS especialidad,Turnos.paciente,Turnos.especialidad as idespecialidad,Turnos.profesional as idprofesional,Turnos.sobreturno FROM Turnos LEFT OUTER JOIN Especialidades ON Turnos.especialidad = Especialidades.especialidad LEFT OUTER JOIN Profesionales ON Turnos.profesional = Profesionales.profesional where Turnos.paciente='" & Paciente & "' and Turnos.estado='reservado' order by 1 desc,2 asc,3 asc,4 asc", Consulta
i = 0
Do While Not con.Registros.EOF

   dato(i, 1) = con.Registros("idprofesional")
   dato(i, 2) = con.Registros("dia")
   dato(i, 3) = con.Registros("hora")
   dato(i, 4) = con.Registros("paciente")
   dato(i, 5) = con.Registros("turno")
   
   If i = 0 Then
        optHor(i).Caption = Format(con.Registros("dia"), "dd/mm/yyyy") & " - " & con.Registros("hora") & "hs. - " & DesEditar(con.Registros("profesional")) & " - " & DesEditar(con.Registros("especialidad"))
        optHor(i).TabIndex = 2
        optHor(i).Left = 120
        optHor(i).Top = 240
        optHor(i).Visible = True
        If con.Registros("sobreturno") Then
            optHor(i).ForeColor = vbRed
        Else
            optHor(i).ForeColor = vbBlack
        End If
    Else
        Load optHor(i)
        optHor(i).Caption = Format(con.Registros("dia"), "dd/mm/yyyy") & " - " & con.Registros("hora") & "hs. - " & DesEditar(con.Registros("profesional")) & " - " & DesEditar(con.Registros("especialidad"))
        optHor(i).TabIndex = optHor(i - 1).TabIndex + 1
        optHor(i).Left = 120
        optHor(i).Top = optHor(i - 1).Top + 360
        optHor(i).Visible = True
        If con.Registros("sobreturno") Then
            optHor(i).ForeColor = vbRed
        Else
            optHor(i).ForeColor = vbBlack
        End If
    End If
    
    con.Registros.MoveNext
    i = i + 1
    DoEvents
Loop
con.CerrarRegistros

'ancho frame horario
frameHor.Height = 360 * i + 735 - 360
Me.Height = 360 * i + (Me.Height - 1305) - 360
'Me.Height = 360 * i + 3075 - 360 + 705

End Sub

Private Sub CargarDatos()

Select Case Tipo
    Case TipoBusHC.Profesional
        frmHCsalida.Profesional = ReplicarCaracter("0", LargoID, cmbProf.ItemData(cmbProf.ListIndex))
        frmHCsalida.Turno = ""
        
    Case TipoBusHC.TurnosPaciente
        For i = 0 To optHor.UBound
            If optHor(i).Enabled And optHor(i).Value Then Exit For
            DoEvents
        Next i
        frmHCsalida.Profesional = dato(i, 1)
        frmHCsalida.Turno = dato(i, 5)
        
End Select

Unload Me

End Sub

Private Sub BusDatos()

Select Case Tipo
    Case TipoBusHC.Profesional
        Me.Caption = "Seleccione Profesional"
        frameHor.Visible = False
        frameProf.Visible = True
        CargarEspecialidades
        
    Case TipoBusHC.TurnosPaciente
        Me.Caption = "Seleccione Turno Paciente: " & DesEditar(con.BusDato("pacientes", "apellido + ', ' + nombre", "paciente='" & Paciente & "'"))
        frameHor.Visible = True
        frameProf.Visible = False
        VerHorariosPaciente Paciente
        
End Select

End Sub
